#include "picture.h"

//准备lcd
void lcd_zhunbei(struct lcd_info *p)
{

    p->fb = open("/dev/fb0",O_RDWR);
    if(p->fb == -1)
    {
        printf("lcd打开失败:%s\n",strerror(errno));
        exit(0);
    }
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    ioctl(p->fb,FBIOGET_VSCREENINFO,&vinfo);
    ioctl(p->fb,FBIOGET_FSCREENINFO,&finfo);
    p->wide   = vinfo.xres;
    p->high   = vinfo.yres;
    p->bpp    = vinfo.bits_per_pixel;
    p->tosize = vinfo.xres*vinfo.yres*vinfo.bits_per_pixel/8;
    //映射2倍大小方便更新可见区
    p->men    = mmap(NULL,p->tosize*2,PROT_READ|PROT_WRITE,
    MAP_SHARED,p->fb,0);
    if(p->men == MAP_FAILED)
    {
        printf("内存映射失败:%s\n",strerror(errno));
        exit(0);
    }
}
//释放lcd相关资源
void lcdsf(struct lcd_info *p)
{
    close(p->fb);
    munmap(p->men,p->tosize*2);
}